package com.flk.oauth.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.io.Serializable;
import java.time.Instant;

/**
 * @author xxwy
 * on 2018/10/15 0015
 */
@MappedSuperclass //标识父类，因为不完整不能映射到数据库中
@Data
public class BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    @Column(updatable = false, nullable = false)
    private Instant createTime;

    @Column(nullable = false)
    @JsonIgnore
    private Instant updateTime;

    @PrePersist
    public void prePersist() {
        createTime = updateTime = Instant.now();
    }

    @PreUpdate
    public void preUpdate() {
        updateTime = Instant.now();
    }
}
